package Selenium.MyAccount;
import java.util.ArrayList;
import org.openqa.selenium.*;



public class GlobalHeaderClass {
	
	//The purpose of this class to create an object of Global Navigation. Making it available 
	//all
	
	
	private WebDriver GenericWebDriver;
	public WebElement GlobalNavObject;
	public boolean GlobalNavObjectExists;
	public boolean LocationIndicatorExists;
	public boolean StorLocatorExists;
	public boolean SiginExists;
	public boolean RegisterExists;
	public boolean ViewBasketExists;
	public ClickableElements GlobalNavClickableObjects;	
	


	
	public GlobalHeaderClass(WebDriver GenericWebDriver)
	{
		//this try statement tries to catch the global header object.
		//In case global header is not found it throws a ElementNotFoundException
		this.GenericWebDriver = GenericWebDriver;
		GlobalNavObjectExists = false;
		LocationIndicatorExists = false;
		StorLocatorExists = false;
		SiginExists = false;
		RegisterExists = false;
		ViewBasketExists = false;
		GlobalNavObjectExists = false;
		GlobalNavClickableObjects = new ClickableElements();		
		try
		{			
			GlobalNavObject = GenericWebDriver.findElement(By.tagName("nav"));
			GlobalNavObjectExists = true;			
		}
		catch(NoSuchElementException ex)
		{
			System.out.println("Global header was not found on the page");
		}		
		ReadClickableElements();
		
	}
	
	
	
	//This method reads the click-able elements and sets there existence flags
	public void ReadClickableElements()	
	{
			
			//try to get the GlobalStoreLocator object
			try
			{
			GlobalNavClickableObjects.LocationIndicator = GlobalNavObject.findElement(By.className("geo"));
			LocationIndicatorExists = true;
			}
			catch(NoSuchElementException ex)
			{
				System.out.println("Store locator element was not found in global header");			
			}
			catch(Exception ex1)
			{
				System.out.println("Store locator element was not found in global header");			
			}
			
			//try to get the Signin link object
			try
			{
			GlobalNavClickableObjects.SignIn = GlobalNavObject.findElement(By.id("sigin")).findElement(By.className("sign-link"));
			SiginExists = true;
			}
			catch(NoSuchElementException ex)
			{
				System.out.println("Sign in element was not found in global header");			
			}
			catch(Exception ex1)
			{
				System.out.println("Sign in element was not found in global header");			
			}
			
			//try to cath the store locator element
			try
			{
			GlobalNavClickableObjects.StoreLocator = GlobalNavObject.findElement(By.className("stores"));
			StorLocatorExists = true;
			}
			catch(NoSuchElementException ex)
			{
				System.out.println("Store locator element was not found in global header");			
			}
			catch(Exception ex1)
			{
				System.out.println("Store locator element was not found in global header");			
			}
			//try to catch the registration element
			try
			{
			java.util.List<WebElement> myList = new ArrayList<WebElement>();
			myList = GlobalNavObject.findElement(By.id("sigin")).findElements(By.tagName("span"));
			GlobalNavClickableObjects.Register = myList.get(1);
			RegisterExists = true;
			}
			catch(NoSuchElementException ex)
			{
				System.out.println("Register element was not found in global header");			
			}
			catch(Exception ex1)
			{
				System.out.println("Register element was not found in global header");			
			}
			
			//trying to catch View basket
			try
			{	
			GlobalNavClickableObjects.ViewBasket = GlobalNavObject.findElement(By.className("basket"));
			ViewBasketExists = true;
			}
			catch(NoSuchElementException ex)
			{
				System.out.println("View basket element was not found in global header");			
			}
			catch(Exception ex1)
			{
				System.out.println("View basket element was not found in global header");			
			}
		
	}
	
	
	
	//this is the class for clickable objects
	//use this class in every custom application object class
	public class ClickableElements
	{
		WebElement LocationIndicator;
		WebElement StoreLocator;
		WebElement SignIn;
		WebElement Register;
		WebElement ViewBasket;
		
	}
	


}
